﻿<%@ WebHandler Language="C#" Class="resclass" %>

using System;
using System.Web;
using System.Data;
using System.Xml;
using Cstudy;

public class resclass : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        string action = context.Request.Params["act"];
        if (action == "get")
        {
            DataSet ds = new Cstudy.BLL.resourcesclass().SelectResourcesClass();
            if (ds != null)
            {
                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    ds.Tables[0].Columns[0].ColumnMapping = MappingType.Attribute;
                }
                ds.DataSetName = "List";
                string xml = ds.GetXml();
                xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + xml;
                context.Response.ContentType = "text/xml";
                context.Response.Write(xml);
                context.Response.End();
            }
        }
        else if (action == "add")
        {
            Cstudy.MODEL.resourcesclass resclass = new Cstudy.MODEL.resourcesclass();
            resclass.ClassName = context.Request.Params["cname"];
            resclass.Descscript = context.Request.Params["des"];
            int result=0;
            if (AddClass(resclass))
                result = 1;
            context.Response.Write(result);
            context.Response.End();
        }
        else if (action == "del")
        {
            int classid = int.Parse(context.Request.Params["cid"]);
            int result = 0;
            if (new Cstudy.BLL.resourcesclass().DeleteResourcesClass(classid))
                result = 1;
            context.Response.Write(result);
            context.Response.End();
        }
        else if (action == "edit")
        {
            Cstudy.MODEL.resourcesclass resclass = new Cstudy.MODEL.resourcesclass();
            resclass.ClassName = context.Request.Params["cname"];
            resclass.Descscript = context.Request.Params["des"];
            resclass.ClassID = int.Parse(context.Request.Params["cid"]);
            int result = 0;
            if (new Cstudy.BLL.resourcesclass().UpdateResourcesClass(resclass))
                result = 1;
            context.Response.Write(result);
            context.Response.End();
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

    private bool AddClass(Cstudy.MODEL.resourcesclass resclass)
    {
        return new Cstudy.DAL.resourcesclass().AddResourcesClass(resclass);
    }

}